package com.ltmall.api.parse;

import com.ltmall.api.comm.Path;
import com.ltmall.api.entity.JsonComment;
import com.ltmall.api.entity.JsonScore;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class CommentParse {
    //商品图片的路径
    static String photoPath = Path.nginx_server_dir_client + Path.PHOTO + File.separator;

    //订单列表列表的解析
    public static List<JsonComment> commentListParse(List<?> list) {
        List<JsonComment> commentList = new ArrayList<JsonComment>();
        for (int i = 0; i < list.size(); i++) {
            Object[] obj = (Object[]) list.get(i);
            JsonComment comment = new JsonComment();

            comment.setUserID(Integer.parseInt(obj[0].toString()));
            comment.setUserName((obj[1] == null) ? null : obj[1].toString());
            comment.setUserPhoto(photoPath + ((obj[2] == null) ? null : obj[2].toString()));
            comment.setComment((obj[3] == null) ? null : obj[3].toString());
            comment.setOpTime(Long.parseLong(obj[4].toString()));
            comment.setGoodsRating(Float.parseFloat(obj[5].toString()));
            comment.setUserPhone((obj[6] == null) ? null : obj[6].toString());

            commentList.add(comment);
        }
        return commentList;
    }

    public static JsonScore scoreParse(List<?> list) {
        JsonScore score = new JsonScore();
        Object[] obj = (Object[]) list.get(0);
        score.setDescribeScore((obj[0] == null) ? 5 : Float.parseFloat(obj[0].toString()));
        score.setServiceSocre((obj[1] == null) ? 5 : Float.parseFloat(obj[1].toString()));
        score.setSpeedScore((obj[2] == null) ? 5 : Float.parseFloat(obj[2].toString()));
        return score;
    }

}
